package com.example.androidlearning2422.ui.kotlin

fun main(){
    sum1()
    sum2()
    sum3()
    sum4()
    //求班级平均成绩
    val scores = intArrayOf(88,100,87,79,65,45,74,98)
  /*  var sum =0
    for (score in scores){
        sum += score
    }*/
    val average = scores.sum()/scores.size
    println(average)
}
private fun sum4(){
    var sum = 0
    for (i in 100 downTo  1 step 2){
        sum += i
    }
    println(sum)
}
private fun sum3(){
    var sum = 0
    for (i in 1 .. 100 step 2){
        sum += i
    }
    println(sum)
}
private fun sum2(){
    var sum = 0
    for (i in 1 until 100 step 2){
        sum += i
    }
    println(sum)
}
private fun sum1(){
    var sum = 0
    for (i in 1 .. 100 step 2){
        sum += i
    }
    println(sum)
}